export function query(url, method = 'GET', data, headers) {
    const baseURL = `https://cnodejs.org/api/v1`;
    const options = {
        method,
        headers: Object.assign({
            'Content-Type': 'application/json'
        }, headers)
    }
    if (data) {
        options.body = JSON.stringify(data);
    }
    return fetch(`${baseURL}${url}`, options).then(response => response.json());
}

export function dateFmt(input) {
    const obj = new Date(input);
    const y = obj.getFullYear();
    const m = obj.getMonth() + 1;
    const d = obj.getDate();
    const h = obj.getHours();
    const mm = obj.getMinutes();
    const s = obj.getSeconds();
    return `${y}-${m}-${d} ${h}:${mm}:${s}`;
}